package com.caipiao.lottery.lty.patch;

public class Patch
{
	public static void main(String[] args)
	{
		//String code = "1,2,12,13*4,7,18|6*7,14";
		
		String code = "01,02,12,13*04,07,18|06*07,14";
		
		System.out.println(code);
		
		code = ChangeDLTCode("DLT", code);
		
		System.out.println(code);
	}
	
	public static String ChangeDLTCode(String lotteryId, String code)
	{
		String rtnCode = code;
		do
		{
			try
			{
				if (null == lotteryId || !lotteryId.equalsIgnoreCase("DLT"))
				{
					break;
				}
				
				String[] win_code_list = code.split("[|]");
				
				if (win_code_list.length == 2)	//前后两区
				{
					rtnCode = GetLeTouCode(win_code_list[0]) + "|" + GetLeTouCode(win_code_list[1]);
				}
			}
			catch(Exception e)
			{
				rtnCode = code;
			}
		}
		while(false);
		
		return rtnCode;
	}
	
	static String GetLeTouCode(String code)
	{
		String[] code_list = code.split("[*]");
		
		if(code_list.length == 1)   //单复式
		{
			return ChangeCodeSeq(code_list[0]);
		}
		else if (code_list.length == 2)	//胆拖
		{
			return ChangeCodeSeq(code_list[0]) + "*" + ChangeCodeSeq(code_list[1]);
		}
		else 
		{
			return code;
		}
	}
	
	//1,2,15,16  补位
	static String ChangeCodeSeq(String code)
	{
		StringBuffer buff = new StringBuffer();
		String[] code_list = code.split(",");
		
		int k=0;
		for(String code_ : code_list)
		{
			if (k>0)
			{
				buff.append(",");
			}
			
			buff.append(alignCode(code_));
			
			k++;
		}
		
		return buff.toString();
	}
	
	//加0补齐
	static String alignCode(String code)
	{
		int code_ = Integer.valueOf(code);
		return String.format("%02d", code_); 
	}
}
